<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单强制结束申请列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>订单渠道：</label>
                            <select name="channel" th:with="type=${@dict.getType('sys_used_channel')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>租借类型：</label>
                            <select name="mode" th:with="type=${@dict.getType('sys_used_borrow_mode')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>审批状态</label>
                            <select name="auditStatus" th:with="type=${@dict.getType('end_order_audit_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li class="select-time">
                            <label style="width: 105px;">申请时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="startTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>

                        <li>
                            <label style="width: 105px;">关键字查询字段：</label>
                            <select name="fields">
                                <option value="orderNumber" selected>订单号</option>
                                <option value="storeName">门店名称</option>
                            </select>
                            <input type="text" name="keywords"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:endOrder:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:endOrder:remove')}]];

    var refuseFlag = [[${@permission.hasPermi('system:endOrder:refuseCz')}]];
    var endUsedFlag = [[${@permission.hasPermi('system:endOrder:endUsed')}]];

    var auditStatusDatas = [[${@dict.getType('end_order_audit_status')}]];
    var channelDatas = [[${@dict.getType('sys_used_channel')}]];
    var modeDatas = [[${@dict.getType('sys_used_borrow_mode')}]];
    var prefix = ctx + "system/endOrder";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "订单强制结束申请",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'partnerName',
                    title: '直营合作商'
                },
                {
                    field: 'merchantName',
                    title: '直营商户'
                },
                {
                    field: 'storeName',
                    title: '门店名称'
                },
                {
                    field: 'createTime',
                    title: '申请时间'
                },
                {
                    field: 'channel',
                    title: '订单渠道',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(channelDatas, value);
                    }
                },
                {
                    field: 'mode',
                    title: '租借类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(modeDatas, value);
                    }
                },
                {
                    field: 'orderNumber',
                    title: '订单号'
                },
                {
                    field: 'usingTime',
                    title: '开始租借时间'
                },
                {
                    field: 'reason',
                    title: '申请结束原因'
                },
                {
                    field: 'auditStatus',
                    title: '审批状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(auditStatusDatas, value);
                    }
                },
                {
                    field: 'auditTime',
                    title: '审批时间'
                },
                {
                    field: 'remark',
                    title: '拒绝描述'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];


                        if (row.auditStatus == 1) {
                            // 拒绝审核
                            actions.push('<a class="btn btn-danger btn-xs ' + refuseFlag + '" href="javascript:void(0)" onclick="refuseCz(\'' + row.id + '\')"><i class="fa fa-remove"></i>拒绝</a> ');

                            actions.push('<a class="btn btn-info btn-xs ' + endUsedFlag + '" href="javascript:void(0)" onclick="endUsed(\'' + row.id + '\')"><i class="fa fa-database"></i>审批通过并结束订单</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function refuseCz(id) {
        var url = prefix + "/refuseCz/" + id;
        $.modal.open("拒绝申请", url, 800, 600);
    }

    function endUsed(id) {
        // 结束租借订单
        var url = prefix + "/endUsed/" + id;
        $.modal.open("强制结束订单", url, 800, 460);
    }
</script>
</body>
</html>